// Tags:
#include <cstdio>
#include <iostream>
#include <queue>

const int N = 1e4 + 5;
int n, maxd;
std::vector<int> obj[N];
std::priority_queue<int, std::vector<int>, std::greater<int> > pq;

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("UVA1316 Supermarket.in", "r", stdin);
  freopen("UVA1316 Supermarket.out", "w", stdout);
#endif
#endif

  while (std::cin >> n) {
    maxd = 0;
    for (int i = 1; i < N; ++i) obj[i].clear();
    for (int i = 1, p, d; i <= n; ++i) {
      scanf("%d%d", &p, &d);
      maxd = std::max(maxd, d);
      obj[d].push_back(p);
    }
    for (int i = 1; i <= maxd; ++i) {
      for (auto j : obj[i]) {
        if (pq.size() < (size_t)i) pq.push(j);
        else if (pq.top() < j)
          pq.pop(), pq.push(j);
      }
    }
    int ans = 0;
    while (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
    printf("%d\n", ans);
  }
  return 0;
}